// pages/selecttranscripts/selecttranscript.js
import https from '../../utils/Newrequests'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        classList: [],
        classitem: {},
        selectTypeName: "",
        idSS: "",
        teacherAnalysisQuery:1
    },
    sscoreanalysis(e) {
        const { selectTypeName, idSS } = this.data;  // 获取参数
        let subjectGroup = 0;  // 默认设置为 0

        // 根据 selectTypeName 设置 subjectGroup
        if (selectTypeName === '3+1+2') {
            if (e.currentTarget.dataset.id === '1') {
                subjectGroup = 2;  // 物理
            } else if (e.currentTarget.dataset.id === '2') {
                subjectGroup = 1;  // 历史
            }
        }

        // 跳转到 Newscoreanalysis 页面，带上 examId 和 subjectGroup
        wx.navigateTo({
            url: `/pages/Newscoreanalysis/Newscoreanalysis?examId=${idSS}&subjectGroup=${subjectGroup}`
        });
    },

    cscoreanalysis(e) {
        const { selectTypeName,idSS } = this.data;
        let subjectGroup = 0;
        const item = e.currentTarget.dataset.index;
        // console.log(item, '点击的班级信息');
        const classId = item.id;
        if (selectTypeName === '3+1+2') {
            if (e.currentTarget.dataset.id === '1') {
                subjectGroup = 2;  // 物理
            } else if (e.currentTarget.dataset.id === '2') {
                subjectGroup = 1;  // 历史
            }
        }
        wx.setStorageSync('classInfo', item)
        wx.navigateTo({
            url: `/pages/Newclassanalysis/Newclassanalysis?examId=${idSS}&subjectGroup=${subjectGroup}&classId=${classId}&selectTypeName=${selectTypeName}`,
        });
    },

    async getClassList() {
        let { idSS } = this.data
        const examId = idSS
        let that = this
        if (wx.getStorageSync('userInfo')) {
            let id = wx.getStorageSync('userInfo').user.userName
            let options = {
                url: '/analysis/total/score/getClassList',
                method: 'get',
                data: { examId },
                header: { "content-type": "application/json;charset=UTF-8" },
            }
            let res = await https(options)
            if (res.data.code == 200) {
                console.log(res.data.data);

                this.setData({ classList: res.data.data })
            } else {
                wx.showToast({
                    title: res.data.msg,
                    icon: 'success',
                    duration: 2000 //持续的时间
                })
            }
        } else {
            wx.redirectTo({
                url: '/pages/teacherlogin/teacherlogin',
            })
        }
    },
    //配置获取
    async getSchoolConfig() {
        let { idSS } = this.data
        const examId = idSS
        let options = {
            url: `/analysis/gradeQueryPermissionConfig/getSchoolConfig/${examId}`,
            method: 'get',
            header: { "content-type": "application/json;charset=UTF-8" },
        };
        let res = await https(options)
        if (res.data.code == 200) {
            console.log(res.data.data, "配置信息");
            this.setData({
                teacherAnalysisQuery: res.data.data.teacherAnalysisQuery
            })
        } else {
            wx.showToast({
                title: res.data.msg,
                icon: 'success',
                duration: 2000
            })
        }
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        const { selectTypeName, id } = options;
        // console.log(selectTypeName, "啥");
        // console.log(id, '啥2');

        this.setData({
            classitem: wx.getStorageSync('alaynisData'),
            selectTypeName: selectTypeName,
            idSS: id
        });
        this.getClassList()
        this.getSchoolConfig()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})